package game.controller;

import common.controller.base.BaseController;
import common.model.enums.ClassificationTypeEnum;
import common.model.po.*;
import common.model.response.base.Result;
import game.model.request.SaveProductRequest;
import game.model.vo.ProductGroupVo;
import game.model.vo.ProductRequirementVo;
import game.model.vo.ProductUnlockVo;
import game.model.vo.SearchRecipeVo;
import game.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 前端控制器
 *
 * @author 米泽鹏
 * @since 2024-01-24 下午 07:10
 */
@Api(tags = "Awesome商店管理")
@RestController
@RequestMapping("/game/g-product")
public class GProductController extends BaseController {

	@Resource
	private GProductService service;
	@Resource
	private GItemService itemService;
	@Resource
	private GBuildingService buildingService;
	@Resource
	private GRecipeService recipeService;
	@Resource
	private GClassificationService classificationService;
	@Resource
	private GProductRequirementService requirementService;
	@Resource
	private GProductUnlockService unlockService;

	@ApiOperation(value = "查询所有商品", notes = "查询所有商品")
	@GetMapping("/readOnly/getAllProductGroup")
	public Result<List<ProductGroupVo>> getAllProductGroup() {
		return successWithData(service.getAllProductGroup());
	}

	@ApiOperation(value = "商品新增或更新", notes = "商品新增或更新")
	@PostMapping("/saveProduct")
	public Result<?> saveProduct(@ApiParam(value = "商品新增或更新请求", required = true) @RequestBody @Validated SaveProductRequest request) {
		return service.saveProduct(request);
	}

	@ApiOperation(value = "商品删除", notes = "商品删除")
	@DeleteMapping("/deleteProduct/{id}")
	public Result<?> deleteProduct(@ApiParam(value = "商品id", required = true) @PathVariable Long id) {
		return service.deleteProduct(id);
	}

	@ApiOperation(value = "查询所有物品", notes = "查询所有物品")
	@GetMapping("/readOnly/getAllItem")
	public Result<List<GItem>> getAllItem() {
		return successWithData(itemService.list());
	}

	@ApiOperation(value = "查询所有建筑", notes = "查询所有建筑")
	@GetMapping("/readOnly/getAllBuilding")
	public Result<List<GBuilding>> getAllBuilding() {
		return successWithData(buildingService.list());
	}

	@ApiOperation(value = "查询所有配方", notes = "查询所有配方")
	@GetMapping("/readOnly/getAllRecipe")
	public Result<List<GRecipe>> getAllRecipe() {
		return successWithData(recipeService.list());
	}

	@ApiOperation(value = "获取全部分类（级联选择器）", notes = "获取全部分类（级联选择器）")
	@PostMapping("/readOnly/getProductCascadeClassification")
	public Result<?> getProductCascadeClassification() {
		return successWithData(classificationService.getCascadeClassification(ClassificationTypeEnum.PRODUCT));
	}

	@ApiOperation(value = "根据商品id查询所有商品成本项", notes = "根据商品id查询所有商品成本项")
	@GetMapping("/readOnly/getAllProductRequirementByProductId/{productId}")
	public Result<List<GProductRequirement>> getAllProductRequirementByProductId(@ApiParam(value = "商品id", required = true) @PathVariable Long productId) {
		return successWithData(requirementService.lambdaQuery().eq(GProductRequirement::getProductId, productId).list());
	}

	@ApiOperation(value = "根据商品id查询所有商品解锁项", notes = "根据商品id查询所有商品解锁项")
	@GetMapping("/readOnly/getAllProductUnlockByProductId/{productId}")
	public Result<List<GProductUnlock>> getAllProductUnlockByProductId(@ApiParam(value = "商品id", required = true) @PathVariable Long productId) {
		return successWithData(unlockService.lambdaQuery().eq(GProductUnlock::getProductId, productId).list());
	}

	@ApiOperation(value = "根据商品id查询所有商品成本项Vo", notes = "根据商品id查询所有商品成本项Vo")
	@GetMapping("/readOnly/getAllProductRequirementVoByProductId/{productId}")
	public Result<List<ProductRequirementVo>> getAllProductRequirementVoByProductId(@ApiParam(value = "商品id", required = true) @PathVariable Long productId) {
		return successWithData(requirementService.getAllProductRequirementVoByProductId(productId));
	}

	@ApiOperation(value = "根据商品id查询所有商品解锁项Vo", notes = "根据商品id查询所有商品解锁项Vo")
	@GetMapping("/readOnly/getAllProductUnlockVoByProductId/{productId}")
	public Result<List<ProductUnlockVo>> getAllProductUnlockVoByProductId(@ApiParam(value = "商品id", required = true) @PathVariable Long productId) {
		return successWithData(unlockService.getAllProductUnlockVoByProductId(productId));
	}

	@ApiOperation(value = "根据配方id查询配方详情", notes = "根据配方id查询配方详情")
	@GetMapping("/readOnly/getRecipeDetailById/{recipeId}")
	public Result<SearchRecipeVo> getRecipeDetailById(@ApiParam(value = "配方id", required = true) @PathVariable Long recipeId) {
		return successWithData(recipeService.getRecipeDetailById(recipeId));
	}

}
